﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Fish_Atlantis.ProfessorPanel;

namespace Fish_Atlantis
{
  public static class PublicService
  {
    public static bool PublishRisks(SqlConnection con, int user, IEnumerable<Risk> risks)
    {
        bool flag = true;
        
            string str = "";
            foreach (var risk in risks)
            {
                if (risk.RiskLevel == 1) { }
                else if (risk.RiskLevel == 2)
                {
                    string content = "---" + risk.Fishery.Name.ToString() + ":Moderate Risk---\n" + risk.Comment.Trim();
                    str = @"insert into Message(SenderID,FisheryID,Content_Text,Time,Message_Type) values('" + user + "','" + risk.Fishery.Id + "','" + content + "','" + DateTime.Now.ToString() + "','1');";
                    flag= Helper.ExecSQL(con, str);
                    if (flag == false) break;
                  
                }
                else
                {
                    string content = "---" + risk.Fishery.Name.ToString() + ":High Risk---\n" + risk.Comment.Trim();
                    str = @"insert into Message(SenderID,FisheryID,Content_Text,Time,Message_Type) values('" + user + "','" + risk.Fishery.Id + "','" + content + "','"+DateTime.Now.ToString()+"','1');";
                    flag = Helper.ExecSQL(con, str);
                    if (flag == false) break;
                }
            }
            return flag;
       
       
      
    }
  }
}
